package com.example.apigateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class ApiGatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApiGatewayApplication.class, args);
    }

    @SpringBootApplication
    public class DemogatewayApplication {
        @Bean
        public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {

            return builder.routes()
                    //名为tobaidu，/baidu 的路径的请求发送到https://www.baidu.com
                    .route("tobaidu", r -> r.path("/bilibili")
                            .uri("https://www.bilibili.com/"))
                    .route("toyupiicu", r -> r.path("/yupiicu")
                            .uri("http://yupi.icu"))

                    .build();
        }
    }
}
